import { Controller, Get, Post, Body, Param, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { GatewayService } from './gateway.service';

@ApiTags('网关')
@Controller('gateway')
export class GatewayController {
  constructor(private readonly gatewayService: GatewayService) { }

  @Get('services')
  @ApiOperation({ summary: '获取服务列表' })
  @ApiResponse({ status: 200, description: '获取服务列表成功' })
  getServices() {
    return this.gatewayService.getServices();
  }

  @Get('routes')
  @ApiOperation({ summary: '获取路由列表' })
  @ApiResponse({ status: 200, description: '获取路由列表成功' })
  getRoutes() {
    return this.gatewayService.getRoutes();
  }

  @Post('proxy/:service/*')
  @ApiOperation({ summary: '代理请求到微服务' })
  @ApiResponse({ status: 200, description: '代理请求成功' })
  proxyRequest(
    @Param('service') service: string,
    @Param('*') path: string,
    @Body() body: any,
    @Query() query: any,
  ) {
    return this.gatewayService.proxyRequest(service, path, body, query);
  }
}

